<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>葡萄病虫害监控系统</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        
        .header {
            background-color: #2c3e50;
            color: white;
            padding: 20px;
            text-align: center;
            border-radius: 10px;
            margin-bottom: 20px;
        }
        
        .container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }
        
        .card {
            background: white;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            padding: 20px;
            transition: transform 0.3s ease;
        }
        
        .card:hover {
            transform: translateY(-5px);
        }
        
        .card h3 {
            margin-top: 0;
            color: #2c3e50;
            border-bottom: 2px solid #3498db;
            padding-bottom: 10px;
        }
        
        .sensor-value {
            font-size: 2em;
            font-weight: bold;
            text-align: center;
            margin: 10px 0;
        }
        
        .sensor-unit {
            font-size: 0.8em;
            color: #7f8c8d;
        }
        
        .status {
            display: inline-block;
            padding: 5px 10px;
            border-radius: 20px;
            font-weight: bold;
        }
        
        .status-normal {
            background-color: #2ecc71;
            color: white;
        }
        
        .status-warning {
            background-color: #f39c12;
            color: white;
        }
        
        .status-danger {
            background-color: #e74c3c;
            color: white;
        }
        
        .chart-container {
            background: white;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            padding: 20px;
            margin-bottom: 20px;
        }
        
        .alerts {
            background: white;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            padding: 20px;
        }
        
        .alert-item {
            padding: 10px;
            margin: 10px 0;
            border-left: 5px solid #e74c3c;
            background-color: #fdf2f2;
        }
        
        .alert-time {
            font-size: 0.8em;
            color: #7f8c8d;
        }
        
        .refresh-btn {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1em;
            margin: 10px 0;
        }
        
        .refresh-btn:hover {
            background-color: #2980b9;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>🍇 葡萄病虫害监控系统</h1>
        <p>实时监控葡萄园环境参数和病虫害风险</p>
    </div>
    
    <button class="refresh-btn" onclick="refreshData()">刷新数据</button>
    
    <div class="container">
        <div class="card">
            <h3>🌡️ 环境温度</h3>
            <div class="sensor-value"><span id="temperature">25.6</span> <span class="sensor-unit">°C</span></div>
            <div>状态: <span class="status status-normal" id="temp-status">正常</span></div>
        </div>
        
        <div class="card">
            <h3>💧 环境湿度</h3>
            <div class="sensor-value"><span id="humidity">65</span> <span class="sensor-unit">%</span></div>
            <div>状态: <span class="status status-normal" id="humidity-status">正常</span></div>
        </div>
        
        <div class="card">
            <h3>🌱 土壤湿度</h3>
            <div class="sensor-value"><span id="soil-moisture">420</span></div>
            <div>状态: <span class="status status-normal" id="soil-status">正常</span></div>
        </div>
        
        <div class="card">
            <h3>☀️ 光照强度</h3>
            <div class="sensor-value"><span id="light">8500</span> <span class="sensor-unit">lux</span></div>
            <div>状态: <span class="status status-normal" id="light-status">正常</span></div>
        </div>
        
        <div class="card">
            <h3>🏭 CO2浓度</h3>
            <div class="sensor-value"><span id="co2">420</span> <span class="sensor-unit">ppm</span></div>
            <div>状态: <span class="status status-normal" id="co2-status">正常</span></div>
        </div>
        
        <div class="card">
            <h3>⚠️ 病虫害风险</h3>
            <div class="sensor-value"><span id="risk">低</span></div>
            <div>状态: <span class="status status-normal" id="risk-status">正常</span></div>
        </div>
    </div>
    
    <div class="chart-container">
        <h3>📈 环境参数趋势图</h3>
        <canvas id="chart" width="400" height="200"></canvas>
    </div>
    
    <div class="alerts">
        <h3>🔔 最新警报</h3>
        <div id="alert-list">
            <div class="alert-item">
                <strong>高温警告</strong>
                <p>温度达到36.2°C，超过阈值35°C</p>
                <div class="alert-time">2023-06-15 14:32:45</div>
            </div>
            <div class="alert-item">
                <strong>低湿警告</strong>
                <p>湿度降至38%，低于阈值40%</p>
                <div class="alert-time">2023-06-15 10:15:22</div>
            </div>
        </div>
    </div>
    
    <script>
        // 模拟数据刷新
        function refreshData() {
            // 模拟从服务器获取数据
            const temp = (20 + Math.random() * 15).toFixed(1);
            const humidity = (50 + Math.random() * 30).toFixed(0);
            const soilMoisture = (300 + Math.random() * 200).toFixed(0);
            const light = (5000 + Math.random() * 5000).toFixed(0);
            const co2 = (400 + Math.random() * 200).toFixed(0);
            
            // 更新页面数据
            document.getElementById('temperature').textContent = temp;
            document.getElementById('humidity').textContent = humidity;
            document.getElementById('soil-moisture').textContent = soilMoisture;
            document.getElementById('light').textContent = light;
            document.getElementById('co2').textContent = co2;
            
            // 更新状态
            updateStatus('temp-status', temp > 35 || temp < 10);
            updateStatus('humidity-status', humidity > 80 || humidity < 40);
            updateStatus('soil-status', soilMoisture < 300);
            updateStatus('light-status', light < 1000);
            updateStatus('co2-status', co2 > 1200);
            
            // 生成随机风险评估
            const risks = ['低', '中', '高'];
            const risk = risks[Math.floor(Math.random() * 3)];
            document.getElementById('risk').textContent = risk;
            updateStatus('risk-status', risk === '高');
        }
        
        function updateStatus(elementId, isWarning) {
            const element = document.getElementById(elementId);
            if (isWarning) {
                element.className = 'status status-danger';
                element.textContent = '异常';
            } else {
                element.className = 'status status-normal';
                element.textContent = '正常';
            }
        }
        
        // 页面加载时刷新一次数据
        window.onload = function() {
            refreshData();
        }
    </script>
</body>
</html>